class Solution:
    def numTrees(self, n):
        """
        :type n: int
        :rtype: int
        """
        if n < 2:
            return n
        dp = [0]*(n+1)
        dp[0] = 1
        for i in range(1, n+1):
            for j in range(0, i):
                dp[i] += dp[j]*dp[i-j-1]# 卡特兰数求平衡二叉树的种数
        return dp[n]
